
import reqApis from "../js/reqApis";
import COS from 'cos-js-sdk-v5'

const uploadImg = (file) => {
    return new Promise((resolve, reject) => {
        reqApis.uploadParamaFn().then(res => {
            console.log(222, res);
            let Cos = new COS({
                SecretId: res.data.accessKey,
                SecretKey: res.data.secretKey,
            })
            Cos.sliceUploadFile({
                Bucket: res.data.bucketName,
                Region: res.data.bucket,
                Key: `images/${(new Date()).getFullYear()}${(new Date()).getMonth()+1}${(new Date()).getDay()}/${new Date().getTime()}-${file.name}.png`,
                Body: file
            }, (error, data) => {
                if(error) {
                    reject(error)
                }else{
                    resolve(data);
                }
            })
        })
    })
}
const uploadUtil = {
    uploadImg
}

export default uploadUtil;